﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// 
    /// </summary>
    public class TopHat : BaseImageFilter
    {
        protected Erode erode = new Erode();
        protected Open open = new Open();
        protected Sub sub = new Sub();

        /// <summary>
        /// Initializes a new instance of the <see cref="TopHat"/> class.
        /// </summary>
        public TopHat()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TopHat"/> class.
        /// </summary>
        /// <param name="_topHat">The _top hat.</param>
        internal TopHat(TopHat _topHat)
        {
        }

        /// <summary>
        /// Execute this Filter
        /// A Debug Statement is written if a concrete Filter is called
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            UnsafeBitmap bitmapOpen = open.ExecuteCloned(_bitmap);
            UnsafeBitmap bitmapResult = sub.Process(bitmapOpen, _bitmap);
            //bitmapDilated.UnlockImage();

            erode.Execute(bitmapResult);

            BitmapFunctions.Copy(bitmapResult, _bitmap);
            return _bitmap; 
        }

        /// <summary>
        /// This is used to clone a filter, each filter must implement it's own clone functionality
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new TopHat(this);
        }
    }
}
